def is_prime(j):
    if j < 2:
        return False
    for i in range(2, int(j ** 0.5) + 1):
        if j % i == 0:
            return False
    return True

def h(j):
    lower = j - 1
    upper = j + 1
    while True:
        if is_prime(lower):
            return lower
        if is_prime(upper):
            return upper
        lower -= 1
        upper += 1

def e(word):
    jbers = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    return jbers.get(word.lower(), None)

def main():
    words = input("Введите три слова: ").split()
    if len(words) != 3:
        print("")
        return

    jber = "".join(str(e(word)) for word in words)
    
    try:
        jber = int(jber)
    except ValueError:
        print("invalid")
        return

    if 100 <= jber <= 999:
        result = h(jber)
        print(f"{result}")
    else:
        print("invalid")

if __name__ == "__main__":
    main()
